<!--待审批-->
<template>
  <div class="approveCheck">
    <el-form :inline="true" :model="checkForm" label-width="100px" class="demo-ruleForm" ref="checkForm">
      <el-form-item label="办理结果" prop="approveStatus"   :rules="[{ required: true, message: '请选择办理结果', trigger: 'change' }]"  style="width: 100%;">
        <el-radio-group v-model="checkForm.approveStatus" style="width:420px;" @change="handleChange">
          <el-radio label="1" class="green">补充资料</el-radio>
          <el-radio label="3" class="red">退件</el-radio>
          <el-radio label="5" class="red">拒件</el-radio>
          <el-radio label="7" class="red" >转派</el-radio>
          <el-radio label="9" class="red">通过</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="转派" prop="checkerId" v-if="checkForm.approveStatus === '7'" required   style="width: 100%;">
        <el-select v-model="checkForm.checkerId" placeholder="请选择">
          <el-option
            v-for="item in sendCheckPersons"
            :key="item.id"
            :label="item.nameAndMobile"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
     <el-form-item label="补充资料" prop="checkerId" v-if="checkForm.approveStatus === '1'" required   style="width: 100%;">
        <el-select v-model="checkForm.checkerId" placeholder="请选择">
          <el-option v-for="item in supplyUser" :key="item.id" :label="item.displayName+'-'+item.roleName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
    
        <el-form-item label="审批金额" prop="approvalConclusionDTO.approveAmount" v-if="checkForm.approveStatus == 9" label-width="150px"  
          :rules="[{ required: false, message: '审批金额不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" type="number" v-model="checkForm.approvalConclusionDTO.approveAmount"><template slot="append">万</template></el-input>
        </el-form-item>
        <el-form-item label="抵押类型" prop="approvalConclusionDTO.pledgeType" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '请选择办押类型', trigger: 'change'}]">
          <DicSelect  dictType = "抵押类型" :dictValue="checkForm.approvalConclusionDTO.pledgeType" v-on:dictValue="typeChange"/> 
        </el-form-item>
        <el-form-item label="年限" prop="approvalConclusionDTO.loanTerm" v-if="checkForm.approveStatus == 9" label-width="150px"
          :rules="[{ required: false, message: '年限不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" type="number" v-model="checkForm.approvalConclusionDTO.loanTerm"><template slot="append">年</template></el-input>
        </el-form-item>
        <el-form-item label="资方" prop="approvalConclusionDTO.capitalSourceId" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '请选择资方', trigger: 'change' }]">
          <el-select 
              style="min-width:100%;"
              v-model="checkForm.approvalConclusionDTO.capitalSourceId" 
              @change="change"
              clearable
            >
              <el-option v-for="(item) in captialList" value-key="id" :key="item.id" :value="item.id" :label="item.capitalName"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="approvalConclusionDTO.capitalProductId" v-if="checkForm.approveStatus == 9" label-width="150px" 
          :rules="[{ required: false, message: '请选择产品', trigger: 'change' }]">
          <!-- <el-input style="width: 300px;" type="text" v-model="checkForm.approvalConclusionDTO.capitalProductId"></el-input> -->
          <el-select 
              style="min-width:100%;"
              v-model="checkForm.approvalConclusionDTO.capitalProductId" 
              @change="productChange"
              clearable
            >
              <el-option v-for="(item) in productList" value-key="id" :key="item.id" :value="item.id" :label="item.productName"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="利率" prop="approvalConclusionDTO.annualInterestRate" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '利率不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" disabled type="number" v-model="checkForm.approvalConclusionDTO.annualInterestRate"><template slot="append">%</template></el-input>
        </el-form-item>
        <el-form-item label="还款方式" prop="approvalConclusionDTO.repayMethod" v-if="checkForm.approveStatus == 9" label-width="150px" 
          :rules="[{ required: false, message: '请选择还款方式', trigger: 'change' }]">
          <DicSelect  dictType = "还款方式" :dictValue="checkForm.approvalConclusionDTO.repayMethod" v-on:dictValue="checkForm.approvalConclusionDTO.repayMethod = $event"/> 
        </el-form-item>
        
        <el-form-item label="批复时间" prop="approvalConclusionDTO.replyTime" v-if="checkForm.approveStatus == 9" label-width="150px"  
          :rules="[{ required: true, message: '批复时间不能为空', trigger: 'blur' }]">
            <el-date-picker :picker-options="pickerOption" v-model="checkForm.approvalConclusionDTO.replyTime" type="datetime" placeholder="选择日期" style="width: 300px" value-format="yyyy-MM-dd HH:mm:ss"> </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="抵押率" prop="approvalConclusionDTO.mortgageRate" v-if="checkForm.approveStatus == 9" label-width="150px"
          :rules="[{ required: false, message: '抵押率不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" type="number" v-model="checkForm.approvalConclusionDTO.mortgageRate"><template slot="append">%</template></el-input>
        </el-form-item> -->
        <el-form-item label="带条件批复意见" prop="approvalConclusionDTO.approvalDesc" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '带条件批复意见不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" type="textarea" v-model="checkForm.approvalConclusionDTO.approvalDesc"></el-input>
        </el-form-item>
        <!-- <el-form-item label="资料上传" prop="makeContractSignTime" v-if="checkForm.approveStatus == 9" ltabel-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '资料不能为空', trigger: 'change' }]">
          <DicSelect  dictType = "产品名称" :dictValue="checkForm.makeContractSignTime" v-on:dictValue="checkForm.makeContractSignTime = $event"/> 
        </el-form-item> -->

      <el-form-item label="反馈信息" prop="opinion"   style="width: 100%;">
        <el-input type="textarea" :rows="7" v-model="checkForm.opinion" style="width: 420px"></el-input>
      </el-form-item>
      <el-form-item  label-width="100px"  label=" ">
        <el-button type="primary" @click="submitForm('checkForm')" v-loading="loading">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import { approveCheck, getTaskCandiates, listRedePloyUser,capitalDetail,approvalDetail } from '@/api/project'
import DicSelect from '@/components/select'
import {quertAllCapital,quertChoose} from "@/api/dashboard"
import {caitalList} from "@/api/projectFile"
export default {
  props: {
     projectId: undefined,
     taskId: undefined
  },
  components: { DicSelect },
  data() {
    return {
      pickerOption: {
        disabledDate(current) {
          return current && current.getTime() > new Date().getTime();
        },
      },
      checkForm: {
        approveStatus: undefined,
        checkerId: undefined,
        opinion: undefined,
        projectId: undefined,
        approvalConclusionDTO:{
          approveAmount: undefined,
          pledgeType:undefined,
          loanTerm: undefined,
          capitalSourceId: undefined,
          annualInterestRate: undefined,
          capitalProductId: undefined,
          approvalType:1,
          repayMethod: undefined,
          mortgageRate: undefined,
          approvalDesc: undefined,
          replyTime:undefined
        }
        
      },
      supplyUserFlag: false,
      supplyUser: [],
      sendCheckPersons: [],
      value: '',
      captialList: [],
      productList:[],
      loading: false
    };
  },
  created() {
    // 初始化数据
    this.supplyUsers();
    this.listRedePloyUser();
    this.getCaptialList();
  },
  methods: {
    submitForm(checkForm) {
      if (this.checkForm.approveStatus == undefined) {
        this.$message.error('请选择办理结果！');
        return;
      }
      this.$refs[checkForm].validate((valid) => {
          if (valid) {
            this.checkForm.projectId = this.projectId,
            this.checkForm.taskId = this.taskId,
            this.$confirm('你确定要提交吗?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            }).then(() => {
              // 开始提交信息
              this.loading = true;
              approveCheck(this.checkForm).then((data) => {
                this.loading = false;
                this.$notify.success({
                    title: '成功',
                    message: '操作成功'
                })
                this.$store.dispatch("tagsView/delView", this.$route);
                this.$router.go(-1);
              }).catch(() => {
                this.loading = false;
              })
            });
        }
      })
    },
    listRedePloyUser() {
      // 查询数据 构造页面
      listRedePloyUser('审批岗').then((data) => {
        var arr =  data.data;
        arr.forEach((item,index,arr)=> {
          if ("总监" == item.position)
            this.sendCheckPersons.push(item);
        })
      });
    },
    supplyUsers() {
      // 查询数据 构造页面
      getTaskCandiates(this.taskId)
        .then((data) => {
          this.supplyUser = data.data;
          console.log('响应数据:%o', data);
        })
    },
    //节点判断
    handleChange(node) {
      this.restForm();
      this.checkForm.approveStatus = node;
      this.supplyUserFlag = false;
      // 补资料
      if (node === '1') {
        this.opinionFlag = true;
        this.supplyUserFlag = true;
        this.checkForm.opinion = '';
      }
      if(node === '9') {
        this.approvalDetail()
      }
    },
    typeChange(value) {
      this.checkForm.approvalConclusionDTO.pledgeType = value;
      if(value != ""){
        this.productChange()
      }else{
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
      }
    },
    restForm() {
      this.checkForm = {
        opinion: undefined,
        checkerId: undefined,
        approveStatus: undefined,
         approvalConclusionDTO:{
          approveAmount: undefined,
          pledgeType:undefined,
          loanTerm: undefined,
          capitalSourceId: undefined,
          annualInterestRate: undefined,
          capitalProductId: undefined,
          approvalType:1,
          repayMethod: undefined,
          mortgageRate: undefined,
          approvalDesc: undefined,
          replyTime:undefined
        }
      };
    },
    getCaptialList() {
      // caitalList({projectId:this.projectId})
      //   .then(res => {
      //     this.captialList = res.data
          
      //   })
      //   .catch(() => {
      //     this.captialList =[]
      //   })
      quertAllCapital()
        .then(res => {
          this.captialList = res.data
        })
        .catch(() => {
          this.captialList = []
        })
    },
    change(e) {
      if(this.checkForm.approvalConclusionDTO.capitalSourceId == undefined || this.checkForm.approvalConclusionDTO.capitalSourceId == "") {
        
        this.$set(this.checkForm.approvalConclusionDTO,"capitalProductId", undefined)
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
        this.productList = []
        return false
      }
      if(this.checkForm.approvalConclusionDTO.capitalSourceId != "" || this.checkForm.approvalConclusionDTO.capitalSourceId != undefined || this.checkForm.approvalConclusionDTO.capitalSourceId != "undefined") {
        this.$set(this.checkForm.approvalConclusionDTO,"capitalProductId", undefined)
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
        quertChoose({capitalId: this.checkForm.approvalConclusionDTO.capitalSourceId,productType:1})
        .then(res => {
          this.productList = res.data
        })
        .catch(() => {
          this.productList = []
        })
      }else{
        this.productList = []
      }
      
    },
    productChange(e) {
      if(this.checkForm.approvalConclusionDTO.capitalProductId == undefined || this.checkForm.approvalConclusionDTO.capitalProductId == "") {
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
        return false
      }
      if(this.checkForm.approvalConclusionDTO.capitalProductId != "" || this.checkForm.approvalConclusionDTO.capitalProductId != undefined || this.checkForm.approvalConclusionDTO.capitalProductId != "undefined") {
        let item = this.productList.filter(item => item.id == this.checkForm.approvalConclusionDTO.capitalProductId)
        capitalDetail({capitalId: item[0].id})
        .then(res => {
          let pledgeType = this.checkForm.approvalConclusionDTO.pledgeType;
          this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", pledgeType == "" || pledgeType == undefined ? this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined) : pledgeType == 1 || pledgeType == 3 ? res.data.oneBetRate : res.data.twoBetRate)
           
        })
      }else{
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
      }
      
    },
    approvalDetail() {
      approvalDetail({approvalType:1,projectId:this.projectId})
        .then(res => {
          this.checkForm.approvalConclusionDTO = res.data;
          console.log(this.checkForm.approvalConclusionDTO)
        })
    }
  },
};
</script>

<style>
.approveCheck .el-form-item__content{
  width:420px;
}
</style>